package com.csr.csrcheck.controller;

import com.csr.csrcheck.pojo.Flight_check;
import com.csr.csrcheck.pojo.Product;
import com.csr.csrcheck.pojo.Product_type;
import com.csr.csrcheck.service.IFlight_checkService;
import com.csr.csrcheck.service.ProductService;
import com.csr.csrcheck.service.Product_typeService;
import com.csr.csrcheck.service.ex.CompanyException;
import com.csr.csrcheck.service.ex.Flight_checkException;
import com.csr.csrcheck.util.JsonResult;
import com.csr.csrcheck.util.PageResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@RequestMapping({"flight_check"})
@RestController
public class Flight_checkController extends BaseController {
    private static final Logger log = LoggerFactory.getLogger(com.csr.csrcheck.controller.Flight_checkController.class);

    @Resource
    private IFlight_checkService iFlight_checkService;

    @Resource
    private Product_typeService productTypeService;

    @Resource
    private ProductService productService;

    @GetMapping({"flight_checkllist"})
    public JsonResult<List<Flight_check>> Flight_checklist(HttpServletResponse response) throws IOException, ServletException {
        List<Flight_check> list = this.iFlight_checkService.getFlight_checklist();
        if (list == null)
            throw new Flight_checkException("");
        return new JsonResult(Integer.valueOf(0), "json", list);
    }

    @GetMapping({"flight_checkllist2"})
    public JsonResult<List<Flight_check>> Flight_checklist2(HttpServletResponse response) throws IOException, ServletException {
        List<Flight_check> list = this.iFlight_checkService.getFlight_checklist2();
        if (list == null)
            throw new Flight_checkException("");
        return new JsonResult(Integer.valueOf(0), "json", list);
    }

    @GetMapping({"flight_checkllist3"})
    public JsonResult<List<Flight_check>> Flight_checklist3(HttpServletResponse response) throws IOException, ServletException {
        List<Flight_check> list = this.iFlight_checkService.getFlight_checklist3();
        if (list == null)
            throw new Flight_checkException("");
        return new JsonResult(Integer.valueOf(0), "json", list);
    }

    @RequestMapping({"flightcheck"})
    public JsonResult<Object> flightcheck(@RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "5") int pageSize, String company_name, String product_name, String product_t_name, String check_no, String publication) {
        PageResult pageResult = this.iFlight_checkService.getListpage(pageNum, pageSize, company_name, product_name, product_t_name, check_no, publication);
        if (pageResult == null)
            throw new CompanyException("");
                    log.info("flightcheck--------------------------->pageNum:" + pageNum);
        log.info("flightcheck--------------------------->pageSize:" + pageSize);
        log.info("flightcheck--------------------------->company_name:" + company_name);
        log.info("flightcheck--------------------------->product_name:" + product_name);
        log.info("flightcheck--------------------------->product_t_name:" + product_t_name);
        log.info("flightcheck--------------------------->check_no:" + check_no);
        log.info("flightcheck--------------------------->publication:" + publication);
        return new JsonResult(Integer.valueOf(0), "json", pageResult);
    }

    @GetMapping({"productType"})
    public JsonResult<List<Product_type>> productType() {
        List<Product_type> list = this.productTypeService.getlist();
        if (list == null)
            throw new CompanyException("");
        return new JsonResult(Integer.valueOf(0), "json", list);
    }

    @RequestMapping(path = {"addflight"}, method = {RequestMethod.POST})
    public JsonResult<Void> addflight(Flight_check flight_check) {
        this.iFlight_checkService.addFlightcheck(flight_check);
        return new JsonResult(Integer.valueOf(0), "json");
    }

    @RequestMapping(path = {"updateflight"}, method = {RequestMethod.POST})
    public JsonResult<Void> updateflight(Flight_check flight_check) {
        this.iFlight_checkService.updateFlightcheck(flight_check);
        return new JsonResult(Integer.valueOf(0), "json");
    }

    @RequestMapping(path = {"deleteflight/{id}"}, method = {RequestMethod.POST})
    public JsonResult<Void> deleteflight(@PathVariable("id") int id) {
        this.iFlight_checkService.deleteFlightcheck(id);
        return new JsonResult(Integer.valueOf(0), "json");
    }

    @RequestMapping(path = {"findflight/{id}"}, method = {RequestMethod.POST})
    public JsonResult<Flight_check> findflight(@PathVariable("id") int id) {
        Flight_check flight_check = this.iFlight_checkService.findflightByid(id);
        return new JsonResult(Integer.valueOf(0), "json", flight_check);
    }

    @RequestMapping(path = {"listproduct"}, method = {RequestMethod.POST})
    public JsonResult<List<Product>> listproduct() {
        List list = this.productService.list();
        return new JsonResult(Integer.valueOf(0), "json", list);
    }
}
